﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>设备条码档案信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script type="text/html" id="barDemo">

        <a title="条码补打" href="javascript:;" lay-event="print" id="reBar"><i class="layui-icon">&#xe66d;</i></a>
        <a title="条码作废" href="javascript:;" lay-event="del" id="dropBar"><i class="layui-icon">&#xe640;</i></a>
        <a title="查看条码" href="javascript:;" lay-event="view" id="view"><i class="layui-icon">&#xe615;</i></a>

    </script>
    @*<script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>*@
    <script src="~/Content/Scripts/System/qrcode.min.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">

                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="barCode" placeholder="条码编码" autocomplete="off" class="layui-input" id="barCode">

                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="sbCode" placeholder="设备编码" autocomplete="off" class="layui-input" id="sbCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="sbName" placeholder="设备名称" autocomplete="off" class="layui-input" id="sbName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="barTypeName" placeholder="设备类型" autocomplete="off" class="layui-input" id="barTypeName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach" id="btn-view" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                            </div>

                        </form>
                    </div>

                    <div class="layui-card-body" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @*<div id="qrcode"></div>*@
</body>

</html>

<script>
    var barCodes = "";
    var currPage = 1;//首先默认值为1，防止出错
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            if (conditon.includes("#")) {
                conditon = conditon.replace(/\#/g, "%23");
            }
            var dUrl = "../Bar/GetDataList?dataType=sbBar&condition=" + conditon;
            var table = layui.table;
            table.render({
                elem: '#list'
                ,height: 'full-200'   //固定高度-即固定表头固定第一行首行
                , cols: [[ //标题栏
                    //{ type: 'checkbox' }
                     { field: 'id', title: 'ID', width: 80 }
                    , { field: 'barCode', align: 'center',  title: '条码', width: '15%' }
                    , { field: 'sbCode', align: 'center', title: '设备编码', width: '15%', }
                    , { field: 'sbName', align: 'center', title: '设备名称', width: '15%' }
                    , { field: 'barTypeName', align: 'center', title: '设备类型', width: '15%' }
                    , { field: 'right', align: 'center', title: '数据操作', toolbar: '#barDemo', width: '10%', fixed: 'right' }
                ]], done: function (res, curr, count) {
                    $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    TablePowerHide();
                }
                //   , height: $(document).height() - $('#list').offset().top - 20
                , url: dUrl
                , skin: 'row' //表格风格
                , even: true
                , page: { layout: ['count', 'prev', 'page', 'next', 'skip', 'limit'], groups: 1, first: false, last: false}
                , page: true //是否显示分页
                , limits: [20, 35, 50]
                , limit: 20 //每页默认显示的数量
                , id: "tData"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'print') {
                    SSO("reBar", data.barCode+",sb");
                }
                else if (obj.event == 'view') {
                    OpenQRCode(data.barCode,data.sbName);
                    //new QRCode(document.getElementById('qrcode'), data.barCode);
                }
                else if (obj.event == 'del') {
                    layer.confirm('确认要作废选中条码？', function (index) {
                        var info = DelData(data.barCode);
                        if (info.Result) {
                            obj.del();
                        } else {
                            layer.msg(info.Message);
                        }
                        layer.close(index);
                    });
                } 

            });
        });
    }

    function OpenQRCode(barCode,name) {
        layer.open({
            type: 1, // page 层类型
            area: ['700px', '400px'],
            title: name,
            shade: 0.6, // 遮罩透明度
            shadeClose: true, // 点击遮罩区域，关闭弹层
            maxmin: true, // 允许全屏最小化
            anim: 0, // 0-6 的动画形式，-1 不开启
            content: '<div id="qrcode" style="padding: 5% 28%;"></div>',
            success: function () {
                // 简单方式
                //new QRCode(document.getElementById('qrcode'), barCode);

                // 设置参数方式
                var qrcode = new QRCode(document.getElementById('qrcode'), {
                    text: barCode,
                    width: 256,
                    height: 256,
                    colorDark: '#000000',
                    colorLight: '#ffffff',
                    correctLevel: QRCode.CorrectLevel.H
                });

            }
        });
    }


    $(function () {

        WebPowersShow();
        //DictionaryDropDown("bst", "barStatus", "");
        loadData();
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                loadData();
            }
        })

    })
   
    /**
   条码作废
   **/
    function DelData(barCode) {
        var info = undefined;
        $.ajax({
            url: "../Bar/DropSBBarCode",
            data: { barCode: barCode },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {

                info = data;
            }
        });
        return info;
    }

</script>